package io.sqrtqiezi.spark.streaming

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext}

object FileDStream {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setAppName("spark file streaming")
      .setMaster("local[*]")

    val ssc = new StreamingContext(conf, Seconds(5))

    val lines = ssc.textFileStream("lagou-data/log/")
    val words = lines.flatMap(_.split("\\s+"))
    val result = words.map((_, 1)).reduceByKey(_ + _)

    result.print()

    ssc.start()
    ssc.awaitTermination()
  }
}
